package com.cysyz.web.modules.base.permission.tag;

import com.cysyz.web.modules.base.user.domain.SysUser;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * Created by cuiyong on 15/1/24.
 */
public class PermissionIfTag extends SimpleTagSupport{
    private String module;
    private String moduleFunction;

    public PermissionIfTag() {

    }

    @Override
    public void doTag() throws JspException, IOException {

        PermissionChooseTag parent = (PermissionChooseTag) this.getParent();

        SysUser currentLoginUser = parent.getCurrentLoginUser();
        if (currentLoginUser != null) {
            if (parent.getPermissionService().hasPermission(currentLoginUser, module, moduleFunction)) {
                parent.setCheckPass(true);
                getJspBody().invoke(null);
            }
        }
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getModuleFunction() {
        return moduleFunction;
    }

    public void setModuleFunction(String moduleFunction) {
        this.moduleFunction = moduleFunction;
    }

}
